package com.softWang.system.utils;


import org.springframework.security.crypto.codec.Hex;

import java.security.MessageDigest;

/**
 * 工具类，用于对用户的密码和登录名进行组合摘要
 */
public class AuthenticateProvider {

	public static String encodeMd5(String ori){
		try {
			// 创建 MessageDigest 实例并指定 MD5 算法
			MessageDigest md = MessageDigest.getInstance("MD5");
			// 将输入字符串转换为字节数组并计算哈希值
			byte[] messageDigest = md.digest(ori.getBytes("UTF-8"));
			// 将字节数组转换为十六进制字符串
			String md5 = new String(Hex.encode(messageDigest));
			return md5.toUpperCase();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	public static String encodeLoginPasswordOnMd5(String password, String loginName) {
		return encodeMd5(password + loginName);
	}

	/*public static void main(String[] args) {
		String password = "111111";
		String loginName = "sysadmin";
		String md5 = encodeLoginPasswordOnMd5(password, loginName);
		System.out.println(md5);
	}*/
}
